package com.example.jvmdemo.org.fenixsoft.jvm.chapter2;

import lombok.Data;

@Data
public class RuntimeConstantPoolOOM_2 {

    private String s;


    public static void main(String[] args) {
        String str1 = new StringBuilder("计算机").append("软件").toString();
        System.out.println(str1.intern() == str1);

        String str2 = new StringBuilder("ja").append("va").toString();
        System.out.println(str2.intern() == str2);

        String s1 = new String("11") + new String("11");
        s1.intern();
        String s2 = "1111";
        System.out.println(s1 == s2);
        System.out.println(s1.equals(s2));
        System.out.println(s2 == s1.intern());


        String s3 = new String("22");
//        s3.intern();
        String s4 = "22";
        System.out.println(s3 == s4);
        System.out.println(s3.equals(s4));
        System.out.println(s4 == s3.intern());

        String s5 = "33";
        String s6 = "33";
        System.out.println(s5 == s6);
        System.out.println(s5.intern() == s6);
        System.out.println(s5.intern() == s6.intern());

        String s = "111";
        String ss = new String("ss");
        RuntimeConstantPoolOOM_2 runtimeConstantPoolOOM_2 = new RuntimeConstantPoolOOM_2();
        runtimeConstantPoolOOM_2.setS("s1");
        ss(s, ss, runtimeConstantPoolOOM_2);
        System.out.println(s + " " + ss + " " + runtimeConstantPoolOOM_2);
    }

    public static void ss(String s, String ss, RuntimeConstantPoolOOM_2 r) {
        s = "222";
        ss = new String("123") + new String("12");
        r.setS("scs");
    }
}
